in reply to uninitialized value in substitution

You should chomp($user) in there somewhere and the line your getting an error on... why don't you just do
$fields[0] = $user;
That should work if i understand what you are trying to do..