The door itself—not deficits in your memory—is to blame.
Doorways make us forget what we’ve just been thinking about because they signify entering a new environment—and our brain is wired to regard a novel environment as potentially dangerous. Therefore we need to put all our attention on our new surroundings to deal with whatever we might encounter. Psychologists call this ‘triggering an event boundary in your brain’.
Your brain files away your past set of thoughts and memories from the previous room, in order to create a blank slate to take in new information from the new room.
In experiments headed by Dr Radvansky at the University of Notre Dame in Indiana USA, people were asked to choose a number of items from a table and put them in a backpack. The backpack was then taken away and the participants were distracted for a while before being asked to write down from memory the items that they’d chosen. If they had to walk through a doorway before writing down the items, they forgot a lot more than if they sat the test in the same room.