File contents overridden using file.write()