I do not wish to gloss over the painful experiences of Neil T and AZ08, but we need to seek an explanation so this can be avoided in the future. To my mind the authorities have clearly stopped two Brazilian ladies who perhaps were never intending to flout the system, but maybe did not have the knowledge that so many others appear to have, who get allowed entry and then disappear and stay.
We know that to gain entry you need:
Reason for visit
Return ticket
Address
Sufficient means of support
However it is not good enough to believe you can satisfy these requirements, you have to convince an immigration official to this effect (lets imagine you are the person in question).
The first three are quite simple, but the fourth is much harder and without a wad of cash, bank statement with transferable funds or credit cards, especially if you have not actually paid for your ticket yourself.
Finally you may genuinely be visiting a close friend and have managed to get an extended holiday from work - but does the official believe you? How likely are your circumstances to be correct, and what is the possibility that he has seen this a thousand times before and 999 have disappeared?
Your admission to the UK is not a right, but a privilege, and if you fit a profile typical of immigration offenders without a fat file of information and evidence to support your story, what is the guy to do if he thinks he is just doing his job? Remember the vast majority of illegal immigrants entered legally - they just never left.
What do I mean by a fat file of information and evidence? I would say copies of everything you can think of putting your and your friend together for as long as possible, PLUS details of their own (ie the UK citizen's) financial situation, copies of bank statements, employment and residential history and a letter committing that they will be totally responsible for you financially during your stay, PLUS a reason to return to your home country, like a letter from your employer or other comitment.
Oh, and one other thing to make it harder - maybe you speak very little English, although this does not seem to have prevented others...