Write CSV file and configure output directory