Concatenating two variables with an underscore

You can use something like this:

NAME=$(echo ${FILENAME}_${EXTENSION})

This works as well:

NAME=${FILENAME}_${EXTENSION}

Your:

NAME=${FILENAME}_$EXTENSION
NAME=${FILENAME}'_'$EXTENSION

are all fine, so would be:

NAME=${FILENAME}_${EXTENSION}
NAME=$FILENAME'_'$EXTENSION
NAME=$FILENAME\_$EXTENSION
NAME=$FILENAME"_$EXTENSION"

(but certainly not NAME=$(echo ${FILENAME}_${EXTENSION}) as it uses echo and the split+glob operator).

NAME=$FILENAME_$EXTENSION

would have been the same as:

NAME=${FILENAME_}${EXTENSION}

as _ (contrary to \ or ') is a valid character in a variable name.

Your problem is that you had lines delimited with CRLF instead of just LF, which meant that those variable content ended in CR character.

The CR character, when written to a terminal tells the terminal to move the cursor to the beginning of the line. So Hello<CR>_WORLD.TXT<CR> when sent to a terminal would show as _WORLD.TXT (overriding the Hello).