The building needs better security and if you have CCTV, then get lots of signs saying CCTV.
Obviously it's very sad to find someone is in that situation, but that is on our state to help him and everyone in that situation. I agree with you that we're all only ever a payslip or one or two bad decisions away from being homeless ourselves. I've always thought that a country is only as strong as it's weakest and poorest, and the state of housing and homelessness and how we view and deal with drug users with very serious problems is a fucking disgrace. In Scotland they have safe rooms and areas where drug users can go and safely go and use in private without judgement. I suppose you could call the council to find out about any help the guy could get and then advise him about that, but I doubt he'd listen.
As far as how to deal with him, I'd say you're doing the right thing, you have to be firm every time, and try and detach your emotions as much as you can and as horrible as it sounds, think of it as chasing out a stray cat or dog. Just tell them to get out and don't take no for an answer and wait until they go and he'll learn to not go there after a while, save telling him you'll call the police as a last resort. I'm only saying do that because you said you could handle yourself. But, to be fair, he'll probably move on and find somewhere else before too long anyway. We used to have a few people smoking crack behind our building and I'd chase them away every time I saw them and shout at them about kids in the area and that, after a while they just left and stopped coming and I'm pretty sure me shouting at them had nothing to do with it.