Fixed file write issue