Here's a little practical exercise to demonstrate the trick for outputting a string without adding a newline at the end.
Step 1: lubricate with a couple of beers. (They don't actually help, but they make you think they help. That boosts confidence ;-)
Step 2: See how the normal way of outputting a string also outputs a newline after it, which is not what we want:
Step 3: The SET /P command outputs a string as a prompt. It stays on the same line.
SET /P var=Enter something:
Step 4. We don't want to pause for the user to enter anything, so we get our input from NUL:
SET /P var=Enter something:<NUL
Step 5: An undocumented feature is that the SET /P command doesn't need a variable name! So you can do this:
SET /P =Some string<NUL
and it just outputs a string without a newline.
Now, putting it together, we have a loop that reads each line of the file and outputs it without a newline. By surrounding the whole loop in parentheses, thus:
(FOR ... DO (...) ) <in.txt >out.txt
we can redirect input and output just once for the whole loop. You can also redirect inside the loop, but that opens and closes the file each time through the loop, which is inefficient. By surrounding the whole loop in parentheses and redirecting outside the loop, we open the file just once.