Registered saving function to execute on exit.