Added writing to csv file