fix file write error