When you are about to enter a mosque (masjid), recite:
اللَّهُمَّ افْتَحْ لِي أَبْوَابَ رَحْمَتِكَ
Also, when you enter a mosque (masjid), Intend for Sunnat Eitekaf (Itikaf) and say
نَوَيْتُ سُنَّتَ الْاِعْتِكَافِ
As long as you will remain in the mosque the angels will keep on writing