Just use join instead of a loop:
print FH ref($bar) eq "ARRAY" ? join(',', @$bar) : $bar; [download]
In reply to Re^5: Extracting Unique elements by wind in thread Extracting Unique elements by smandape1