You are actually using a line feed or new line character ("\n") instead of a carriage return ("\r"). The short story is that you need this:
Dating back to the era of typewriters, the line feed did just that; it literally fed a new line of paper into the typewriter. The carriage return also followed its namesake; it actually returned the carriage to the left most position, normally a duty done by physically sliding the carriage. Once the first printers appeared, the terminology carried over into computer science and C and sticks with us today.
By looking at the terminal window’s output, the system is doing exactly what it was told to do; it added a new line (went down a line) but stayed at the same horizontal position where it was and continued to print (because the virtual carriage never returned to the left). Therefore, a “\r” character should first return the printing position to the left most column before advancing to the next line with “\n”. Does this make sense?