I want the content as a literal string. No processing or evaluation of the content is desired.
if you want the content as literal text, try this:
/bin/cat >> /root/heredoc << 'EOF'
if [ $(grep -c "$IP_ADDR\|$HOSTNAME" $HOSTS_FILE) -ne 0 ]; then
whatever you have
EOF
note, single quoted the heredoc 'EOF'
here is an example:
kent$ cat << eof
$(echo $HOME)
eof
/home/kent
kent$ cat << 'eof'
$(echo $HOME)
eof
$(echo $HOME)