Deploy ksh script to file from other script

Hi all,

I need to deploy two scripts on around ~100 machines and have only OPSware.
Opsware have the option to execute a script, so I am trying to write a script which dose

cat > script.ksh <<EOF
script to be deployed
EOF

However the script between the two EOFs gets also executed which is a problem.
I have also tried with perl

open FILE,">script.ksh" or die "Write error";
print FILE <<EOF
script to be deployed
EOF

but some parts of the script are still processed.

Here is my code

#!/bin/bash

cat > script.ksh <<EOF
#!/usr/bin/ksh
# Where to save the current rules
IPT_FILE="/var/log/iptables.state"
# Send mail to whom
MAIL="root"
# Should we override the recorded IPT_FILE
# every time a change is detected(this will prevent duplicate messages
OVERRIDE="yes"
 
# Path to iptables - leave it so if you are not sure
IPTABLES=$(which iptables)
 
### CONFIGURATION ENDS HERE
 
check()
{
cmp -s <($IPTABLES -L -n) $IPT_FILE
if [ $? -ne 0 ]
 then
    echo -e "Iptables change detected \n Current iptables rules        Previous iptables rules \n \n `diff -y <($IPTABLES -L -n) $IPT_FILE`" | mail -s "Iptables rules changed on $(hostname -f)" $MAIL
     if [ $OVERRIDE == "yes" ]
      then
      $IPTABLES -L -n > $IPT_FILE
      chmod 600 $IPT_FILE
     fi
    exit 1;
 else
    exit 0;
fi
}
 
initial()
{
 
if [[ -s $IPT_FILE ]]
 then
   check
 else
   $IPTABLES -L -n > $IPT_FILE
   chmod 600 $IPT_FILE
   check
fi
}
 
initial
EOF

Output and debug

Any help is greatly appreciated!