If possible I would use an existing utility for this, likely logrotate. If not then I would look to existing modules as they have probably done a reasonable amount of testing. At a glance Logfile::Rotate seems reasonable, but I don't have any personal experience with it.