file written to properly now, exception thrown after write