indicates that the output record separator $\ is printed at the end of each list. I suspect that the output record separator "$\" has somehow gotten set to "\n" rather than a null value.
At the start of the subroutine, try:
$\ = "";
to reset the output record separator and see if it does the trick.