When a bank gives out a loan, a simultaneous liability and asset is created on their balance sheet, and 'external' funding doesn't fit into this picture... so why do they need to borrow money?
Because banks have to satisfy their capital requirements and they are not able to create high powered money.
Capital requirements are different for different banks because under the current rules they depend on how risky are assets that the bank holds (you can read about that here). Suppose the capital requirement rules require some bank to hold capital worth of 10% of a loan it makes. Then if the bank wants to issue \$100 loan it has to keep \$10 as an extra capital reserve.
A consequence of this is that bank needs to have some extra money not created by the loan. If someone comes asking for \$100 loan they would have to have \$10 as a capital reserve that they cannot create themselves (this is also called high-powered money). To get these reserves they can either borrow money from other banks (which might have excess reserves), central bank (which can create reserves/high-powered money at will) or get deposits. Typically it is hard to attract new deposits quickly enough so most of the time bank is making more loans they have to get extra capital for their capital requirements by borrowing either from central bank or other banks.
Banks issue debt because they need to satisfy various capital requirements set by regulators (in the US, the Fed). What is capital exactly? Basically, capital is the sum of Tier1 capital and Tier2 capital. Tier1 capital is essentially issued equity and retained earnings. Tier2 capital is essentially eligible debt securities that have been issued. See here for a good presentation https://www.davispolk.com/sites/default/files/2017-01-11_davis_polk_federal_reserves_final_rule_on_tlac.pdf
Why do these rules exist ? Essentially the Fed wants to be able to easily wind down a bank without causing chaos as occurred in 2008/9. They envision doing this by causing holders of Tier1 capital to receive zero in bankruptcy (stock goes to zero) and holders of Tier2 capital (debt) will receive haircuts as necessary after the assets are resolved.
For all this to work, banks must have issued enough eligible debt securities, even if they have no immediate use for the funds. That is the case today in the US.
Even if there are no liquidity or capital requirements imposed by regulators a prudent bank, which must make interbank payments as a going concern, must issue a mix of liabilities and equity to retain legal control over its portfolio of assets.
Classify the bank assets as reserves, securities, and loans. Classify the bank liabilities and equity as deposits, borrowings, bonds, and equity. Here the borrowings are short term debt to distinguish from bonds as longer term debt.
If the bank does not issue the mix of liabilities and equity equal to the assets then it will be unable to make interbank payments as the outflow of reserves to other banks in the bank sector. So the bank must actively attract liabilities and equity, so it can keep making its payment obligations through the cash reserve account, so it can expand and hold the asset portfolio in the balance sheet.