The simplest way to get the column headers into the CSV (unless using wildcard columns in the sql select) would be to add a line after line 10:
print OUT "col1,col2,col3\n"; # whatever columns you select in the sql at line 10
To get the column names programmatically is more difficult (eg I can't remember off the top of my head and will have to look it up).