Two thoughts:
- check all the variables you're using ($user, $ip, $_, etc.) are correctly chomped, especially if some of them are coming from user input, which you didn't mention. From the ouput you provided, it looks to me like $_ has a trailing newline.
- use the list syntax of the system command, i.e. system($command, $arg1, $arg2), it's always been considered better (as in safer) from what I've read.
Update: ah, well, 5 replies and problem solved by the time I submitted this... nevermind me.