Fixed incorrect CSV output

Changed how file IO was handled, to properly output the csv file.