I can't confirm this behavior against Kubuntu, in my test I get to lines in the file.
In Ansible shell is using /bin/sh, on Kubuntu /bin/sh is a link to dash. Since echo is a builtin on most shells if not all shell, they may differ some. So it depends on you distribution and what /bin/sh is actually running.
To avoid this problem you could use the Ansible's copy module instead
ansible ubtest -m copy -a 'dest=/tmp/foo content="line 1\nline 2"'