You created a loop by connecting the RX and TX pins. Like you said this will continue for ever. If you disable the 'echo' on the port (that data send will not be echoed at the receiving end). This loop effect should not happen.
According to the man page of stty, you can disable the echo-ing of data by using the -echo parameter. The second parameter also disables the CR -> CRLF conversion. (That is why the newlines keep on growing)
stty -F /dev/ttyAMA0 -echo -onlcr
The Linux Serial HOWTO, Paragraph 11.8 has this to say about this:
Another test is to jumper the transmit and receive pins (pins 2 and 3 of either the 25-pin or 9-pin connector) of a test serial port. Then send something to each port (from the PCs keyboard) and see if it gets sent back. If it does it's likely the port with the jumper on it. Then remove the jumper and verify that nothing gets sent back. Note that if "echo" is set (per stty) then a jumper creates an infinite loop. Bytes that pass thru the jumper go into the port and come right back out of the other pin back to the jumper. Then they go back in and out again and again. Whatever you send to the port repeats itself forever (until you interrupt it by removing the jumper, etc.). This may be a good way to test it as the repeating test messages halt when the jumper is removed.
The pin numbers in the text do not correspond with the ones on the RPi, obviously, but the working in general is the same. The jumper they talk about in the text does the same as you did, connect the RX to the TX.
So this is not a problem, just a side effect of using echo while connecting input to output. If you would like a step-by-step explanation why this happens read the answer on this page from our sister site Unix & Linux.