You use "had (done)" when you're telling a story, and you want to talk about something that happened before what you're describing. This grammatical form is known as "past perfect".
In the example above, "my roommate had left his window open" happened before the speaker spent the night in a hotel.
Here's another example from another post:
I was really sleepy because I had gone out drinking the night before.