echo always emits one newline character after the given arguments (although there are implementations that support a ‑n switch disabling that). If you do not want that use printf{
printf 'abc '
printf 'def '
echo 'xyz'
} > myline
printf instead of echo for portability reasons, so maybe get used to it.