Yes, your use of Time::localtime
is the key. It overrides the built-in localtime. If
you use the built-in, it returns a ctime(3) like
string. But in either case, a ctime string isn't going
to give you that 2004111622 format in most cases. To
get a specific date format, you'd also want to incorporate
something like a call to the POSIX
strftime function.
I can't tell for sure, but it looks like you may also be
trying to stat the base file name only: since you open
the directory, you'd need to prepend the directory.
Otherwise it will only work if you run it from that
directory.