Fix file write issue