Added function to output csv file