The risk with /tmp/foo.$$ is the birthday paradox. For 16-bit PIDs, n ~= sqrt(2 * 65536 ln (1 / (1-0.5)) ~= 300, so a few hundred tempfiles lying around means that clashes are more likely to occur than not.