To avoid temp race attack give temporary files unpredictable
file-names. Temp files usually stored in /tmp tempfile=/tmp/$(basename $0).$$.$RANDOM
Or even better us mktemp
tempfile=$(mktemp /tmp/foobar.$$.XXXXXXXXXX)
For scripts executed by regular users may be
better to use local /tmp ~[[ -d $HOME/tmp ]] || mkdir $HOME/tmp
Temporary Files