It appears that you might create certain memories that are only kept for a short duration when they will be valuable. Once you leave a situation that memory gets wiped clean. Doorways may be a convenient signal that current memories (of whatever you are doing) will no longer be needed (in the new context, in another room). So, strange as it seems, walking through a doorway makes you forget.