Why did he bless Hashem?
Malbim: He thanked Him for his wondrous Chesed in a fortified city. He did not remain in Ke'ilah 1 , which was a fortified city, for there Sha'ul would have besieged him and conquered him. Also refer to 31:23:1:1.
I.e. Hashem answered him via the Urim v'Tumim that if he stays, Ba'alei Ke'ilah will hand him over to Sha'ul (Shmuel I, 23:12).
Why did he say Ki Hifli Chasdo"?
Radak: His salvation was wondrous. This was a Nevu'ah (that he would be saved wondrously).
What is the "Ir Matzor"?
Rashi: It is Ke'ilah, like Sha'ul said "Nisgar Lavo b'Ir Delasayim u'Vri'ach" (Shmuel I, 23:7).
Radak: I was protected as if I was in a fortified city. Matzor refers to strength - "va'Tiven Tzor Matzor Lah" (Zecharyah 9:3).