Modified writerow to use dict comprehension for encoding