Separate pip freeze command from operation

By extracting the logic into `pip.operations.freeze`, the hope is that folks could do a freeze programmatically more easily.

Inspired by #2150