Added csv file writing functionality