That's because system only returns 0 if the command was successful. See system. To write the response to a filehandle, use pipe or write a pipe using open.
Be very careful when just putting user input directly into the command -- it's a big security risk and -T will produce errors.