Added error output if write fails (but no error is returned by program! fix?)