Fix spelling of mktemp and improve error handling