Fix a bug for writing csv files.