Ways to create a temp file:

Using mktemp:

$ mktemp /tmp/file.XXX

The trailing Xs will be replaced with the process number and/or a unique letter combination

Creating a temp dir:

$ mktemp -d /tmp/dir.XXX

Output could be saved into a variable:

TMPDIR=$(mktemp -d /tmp/dir.XXXX)

$$

Using $$:

OUT=/tmp/file.out.$$

Here $$ will be replaced with the current process PID.

$RANDOM

OUT=/tmp/file.out.${RANDOM}

$RANDOM is an internal bash/zsh function (not a constant) that returns a pseudorandom [1] integer in the range 0 - 32767