[agent] utils/findKey perf refactor

removed the path var declaration from the loops

used `_.find` instead of `_.each` to stop the loop if `theKey` is found