Fix file writing