Added csv writer function