I do not argue that a PRNG has a non-zero chance of repetition. But I have found, if only through empirical observation, that a reasonable implementation of this strategy is a good pragmatic solution to the collision problem.

In actual implementation, I would write a loop that attempts, say, ten times, to produce a random directory-name and to create a new directory having that name. (If the loop failed to do so, each time, it would generate a warning message to STDERR, because even one actual collision would be, in my book, quite unexpected.) The loop would not permit the directory to be used if it already existed (thus pushing the “atomicity problem” off to the file system).

The odds of even one name-collision are extremely small; the odds of ten collisions in a row are almost-infinitely smaller.

And once the program has acquired a temporary directory that is all its own, it can build whatever files it wants within that directory, and can do with them as it pleases.

Upon termination, it destroys the directory and its content.

I would probably add a short prefix to the random string, both to make it easier to recognize why a given directory-name is present in /tmp, and to simplify the process of removing them en masse.

One million repetitions later, the same string was never produced twice. I am quite confident that, if I had ten or even a hundred times as much time to waste waiting for Godot to repeat himself, the result would have been exactly the same. So, I think that it is quite defensible to say, “it ain’t nevah gonna” happen. Once you have reduced the probability acceptably close to zero (and of course, have demonstrated in your test-suite that it is, in fact, robust), then ...

A tiny part of that is explainable by your using rand( $#array ) instead of rand( @array ) and therefore never picking the final character in those array, giving 51 * 61**3 := 11576031. But the earlyness of the repeat--as low a 24,000--is way too early to be explained even by the Birthday paradox.

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other