Use mktemp instead of the deprecated tempfile.

This fixes the ambiguous redirect error caused by the tempfile command not existing on some systems.