The problem lies in the renaming of the file. Once you rename the file, $coeodir no longer has the correct filename, so your splitter routine is trying to open a file that does not exist. Pass the new filename to the splitter routine and it should work fine.