I assume that the firm can't issue the P45 until you've returned the money you owe them.
As an example, let's assume that you were overpaid by £100 (gross). £69 of that will have ended up in your pay packet, with £31 being paid to the tax man. (£20 tax and £11 National Insurance). When you pay the £69 back the firm will be able to reclaim the £31 from HMRC.
Since your P45 is a summary of your total earnings and the amount of tax which has been paid on those earnings, your former employer needs to 'get the books straight' before it can issue a final statement relating to those figures.
The absence of a P45 is no bar to employment. You simply need to ask a new employer for a P46. Your tax will eventually even out to where it should be.
Chris