Thanks @oleorhagen, your input was very helpful. There doesn’t necessarily seem an equivalent to -p on OS-X. However, replaced the line with
WORK_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
which Im copied from https://newbedev.com/fix-or-alternative-for-mktemp-in-os-x
and it’s doing the trick.