There are many ways to do it. For me, piping the indented string into sed works nicely.
printf_strip_indent() {
printf "%s" "$1" | sed "s/^\s*//g"
}
printf_strip_indent "this is line one
this is line two
this is line three" > "file.txt"
This answer was based on Mateusz Piotrowski's answer but refined a bit.