The underlying brain phenomenon responsible for this is what is known as an “event boundary”. Our brains compartmentalize events and tie them to the environment, or room, in which they occurred. By moving from one room to the next, the brain effectively creates a file containing all the information about the first room, and what you did there, and tucks it away. It then starts to focus on the second room. Thus, remembering what you intended to do upon leaving the first room is a lot harder than if you had simply crossed from one side of the room to the other.