Ok - here are a few obvious things from first glance:
- Why are you using random numbers for file names ? Start at 1, then increment by 1.
- Where does $exname get initialized ?
- You probably meant strftime "%Y%m%d", localtime (Missing % in front of Y)
- You are overwriting the same file in each "$file loop. Move the random number, and file name concatanation INSIDE the loop
- Close the file you open inside the loop, inside the loop.
- Indent your code better for readability
- Post sample output, and/or expected output.
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams