added csv writing function
output writing now uses csv.DictWriter