Let's take the £ 20,000 mortgage first. You and your friend each have a half share, so you receive £ 10,000. Your friend also receives £ 10,000, what they do with it is immaterial.
Now for the house.
This had a value £ 65,000 + £ 58,000 = £ 123,000. So each half share is £ 123,000 / 2 = £ 61,500.
If your friend gives you £ 3,500 (from the mortgage or another source), you will have paid £ 65,000 - £ 3,500 = £ 61,500 for your half share. Your friend will have paid £ 58,000 + £ 3,500 = £ 61,500. So both have paid the same, exactly half the house's value.
It doesn't matter whether you think the £ 3,500 is taken from the mortgage money or another source, it doesn't matter. From your point of view, think of the house purchase and mortgage as two separate transactions, that will save confusion.