Issuing three talaaqs in the absence of one's wife

Q: I constantly have waswasa regarding different things, such as fears of losing important things and intrusive thoughts about divorce. 

Recently, while driving alone, I had thoughts of talaq, and I became worried about accidentally uttering the word and losing my wife. To counter these thoughts, I ended up saying the statement three times "main tumhy talaq deta hon" with my wife's name, thinking it would stop my mind from repeating it in front of her. 

However, I later read that divorce in isolation might still be valid. I also consulted an Imam at the Masjid, who assured me that the talaq is not valid. I would appreciate your opinion on this matter.

Student in a boarding school sleeping in a place safe from sin

Q: I go to an all boys boarding school, and in the dormitory, when it's time to sleep, there are many boys that watch movies in the rooms, and they do all other sorts of Haraam in the room. 

If there is an alternative place for me to sleep, such as a close by Masjid, or the library, is it permissible for me to sleep in the dormitory?