Added functionality to write CSV files