Write save file at the very end. Saves the game even during unexpected exits