...just like the chdir you use, mkdir is perl built-in function. Avoid the overhead and use that instead. You ask "what's going wrong" but you don't even bother checking for errors at the system call. If it interests you what is going wrong, check return values at your critical points.