Use 'with open' instead of 'open' in get_names()

It's more Pythonic.