in reply to a classic : 'Premature end of script headers' problem

The first argument you're passing to writeCSVfile does not appear to be what you're expecting in that subroutine.

Or at least it looks like you're mixing up $flatfile, $filename and $linename in several places.

also a couple of useless things that are in your code:

@flatfields = ("$sys_time", "$consent", "$user_name", "$company", "$u +ser_email");
is the same as
@flatfields = ($sys_time, $consent, $user_name, $company, $user_email +);
since those values are already strings (and even if they weren't, perl will convert them for you when you treat them as strings anyway).

And map{} does a local $_ already, so there's no need to do an explicit local $_ in your code.

So taking all that in account, you may want

$linename = join(",", map { s/"/""/g; qq("$_") } $sys_time, $consent, +$user_name, $company, $user_email);
instead.