Got writing set up, but file is not being written correctly