File write error handling