Changed creatation of temp file to use mktemp instead