Save the script text to a file (logger.pl), open Terminal and change the file mode to allow execution (chmod u+x /path/to/logger.pl), and call the script within (or without) another a script like this:
logger.pl /path/to/your.log calling-process "log text"
Note the log file will be created if it doesn't already exist.
[robg adds: I haven't tested this one...]

