You could use Class:CSV.
use Class::CSV;
my $csv = Class::CSV->new(
fields => [qw/userid username/]
);
$csv->add_line([2063, 'testuser']);
$csv->add_line({
userid => 2064,
username => 'testuser2'
});
$csv->print();
# 2063,testuser
# 2064,testuser2
Edit: For more libraries, you can search CPAN.