Fixed file writing bug.