Improve reliability of file write