BUG: preserve (object) dtype in factorize
Noticed this issue in https://github.com/pandas-dev/pandas/pull/60116 (which adds an xfail for it):

```python
>>> pd.options.future.infer_string = True
>>> idx = pd.Index(["string", "with", "object", "dtype"], dtype=object)
>>> idx
Index(['string', 'with', 'object', 'dtype'], dtype='object')
>>> idx.factorize()
(array([0, 1, 2, 3]),
 Index(['string', 'with', 'object', 'dtype'], dtype='str'))    # <--- now str dtype
```

I think in general a function like factorize should preserve the dtype, even though a better dtype could be inferred here.
Thanks @jorisvandenbossche  Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

1. Checkout backport branch and update it.

```
git checkout 2.3.x
git pull
```

2. Cherry pick the first parent branch of the this PR on top of the older branch:
```
git cherry-pick -x -m1 13926e5e298acf328b0c1347f008ef3f9c4eb078
```

3. You will likely have some merge/cherry-pick conflict here, fix them and commit:

```
git commit -am 'Backport PR #60118: BUG: preserve (object) dtype in factorize'
```

4. Push to a named branch:

```
git push YOURFORK 2.3.x:auto-backport-of-pr-60118-on-2.3.x
```

5. Create a PR against branch 2.3.x, I would have named this PR:

> "Backport PR #60118 on branch 2.3.x (BUG: preserve (object) dtype in factorize)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the `Still Needs Manual Backport` label once the PR gets merged.

If these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).
                 Manual backport -> https://github.com/pandas-dev/pandas/pull/60174