I only get misaligned output if I intentionally alter the line ending translation of the terminal:
stty ocrnl -onlcr
Perhaps the system() function is doing something to the terminal. Try printing out the tty settings directly "stty -a" and indirectly with system("stty -a"). See if they are different.