in reply to How to print header to a CSV file

You forgot to separate the items of the header-record, e.g. try:

$header_rec = join(',', qw(NAME ID REGION UNIT STATUS));
Furthermore, you should open (give the thee argument version a try) and close the file only once - before writing the header and after writing the last line of data. Otherwise, your program will be slower than necessary. Then, you probably want to use '>' instead of '>>' since the latter appends to an existing file.

The other obligatory hint is Text::CSV since re-inventing CSV processing is not worth the pain (unless it is for educational purpose, I guess).