Save preferences before exiting the game