in reply to system function adds spurious characters to log file

Sounds like a broken shell config. Does sh -c exit output the host name? The weird characters are likely terminal control characters.