Switch to using ksh-specific function definitions

With the POSIX flavor, the traps were not local to the functions,
and interrupting the script at _any_ time would case the files to be
deleted. We only want this if the files are not fully populated yet.