It seems your lines are delimited by \r
instead of \n
.
Use this while loop to iterate the input with use of read -d $'\r'
:
while read -rd $'\r' line; do
echo "$line" | sed 's~</td>~</td>$~g' | cut -d'$' -f2,3,4 >> file.txt
done <<< "$TABLE"