From Generate script in bash and save it to location requiring sudo we have this method, which I like:
sudo tee "$OUTFILE" > /dev/null <<'EOF'
foo
bar
EOF
However, I would like to use that approach to append to an existing file $OUTFILE. The above method overwrites existing file $OUTFILE.
man teeman sudowould fairly quickly point you to the fact that tee is a command in it's own right, thus lead you toman tee.