uses: Fix `--installed` with outdated versions (fixes #27259)

With that option iterate only over `Formula.installed`, otherwise iterate over `Formula`.
This is faster than iterating over all the formulae and checking if it's installed.