Use the filename arg as a base for the temp file. Clean up function while here.