Your script is trying to connect to a mail server on your local computer (localhost) on the SMTP port 25. You probably don't have one running.
Try this:
# telnet locahost 25
You should see something like:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
If you don't you...