In general, opening a file can slow down considerably, if there are already many files in that directory. Your best shot would be, IMO, to limit that number. In a similar manner, it's probably best to use bare filenames into the current directory, or relative filepaths into a subdirectory from a the current root directory, instead of using absolute filepaths, in order to avoid the lookup of the directory over and over again, for each file.
HTH.