in reply to system call and newline interpretattion.
Looks like like $_ ends with a newline. Try adding chomp before $command = ....
Unrelated, try using <code> tags around your code and output when you post.