As far as I know, removing these lines fixes the problem. What I see was happening is in the file browser the header was at the top, but when the space was swapping it stored the header location from the old space, and set the header in the new space to that same location. So the file browser had a top aligned header, and when it switched back to the preferences it aligned the header with the top.
I could replicate the problem by going to a shader editor (for example), adding an image texture node, and clicking open. In the file browser I would flip the header to the bottom, then I chose an image. The header in the node editor would be flipped to the bottom after the switch. Removing these lines of code fixes this as well.