establishStream calls writeFile to write the header of the csv asynchronously. Then, writeDataToCSV calls write on a stream to the same file. If the writeFile in establishStream does not finish before the write in writeDataToCSV, then the data from the write is lost.
Sometimes, the first round of output for a game is not logged by writeDataToCSV. I'm under the impression that this is caused by the following:
At this line 62, writeDataToCSV calls establishStream (see https://github.com/hawkrobe/reference_games/blob/master/experiments/sharedUtils/sharedUtils.js#L62 )
establishStream calls writeFile to write the header of the csv asynchronously. Then, writeDataToCSV calls write on a stream to the same file. If the writeFile in establishStream does not finish before the write in writeDataToCSV, then the data from the write is lost.