Bug fix where the header of the CSV file could be written multiple times