Here is the offending part of my script:
read -d \'\' TEXT <<\'EOF\'
Some Multiline
text that
I would like
in
a
var
EOF
echo \"$TEXT\" > ~/some/f
The -d option to read is a feature unique to bash, not part of the POSIX standard (which only specifies -r and -p options to read). When you run your script with sh on Ubuntu, it's getting run with dash, which is a POSIX shell, and not bash. If you want the script to run under bash then you should run it with bash, or give it a #!/bin/bash shebang. Otherwise, it should be expected to run under any POSIX sh.