write to file IO bugfix