use collectFirst instand of a var and iterate

Iterators are lazy, however. If listFilesSafely were changed to return an iterator instead of list, this would subtly change behavior here. I am not for this change, as it makes the behavior less obvious. The prior form clearly indicated the intended and actual behavior; here it is not clear which one is intended, even if it is clear to the particular reader which one is actually occurring.