Ensure that the prefix always has a trailing separator.

Done in the laziest way possible. Also, untested.
Write encode script to a temp directory.

Also don't delete it any more because it's a small file and temp dirs
should get automatically cleaned at least during reboots.

Just use /tmp/ on *nix because TMPDIR is defined on OS X but not Linux.
Update lua script.