If nobody has said anything to your friend, he or she should not be worried yet. But he ought to get himself some help ASAP to get rid of his drug dependency before the state does find and report him. It is getting increasingly hard to pull this off and it does get prosecuted.
Yes, there is a state data base -- I linked you to that -- and many states voluntarily share information, so we're moving in the direction of a national data base. All NYS pharmacies are required to fill these prescriptions electronicaly.
Controlled substances can only be had in a 30 day supply. If he has more than a 30 day supply he can be charged with unlawful possession of a controlled substance. That's what I meant by having more than what's available for personal use. You are not allowed to stockpile these. The doctor shopping law which I already quoted you -- see section 4 -- allows for the possession to be prosecuted criminally.
Yes, it's illegal. Outside of the Health Law above, this could proceed as a drug diversion fraud which would be an A misdemeanor
with a maximum penalty of a year in jail, but could also proceed along the lines of a drug possession case.(look at section 4 of the law I cited in my first answer). Precisely how serious a drug case would depend upon how many pills were illegally possessed and the weight of the controlled substance possessed.
Either way, although prison is possible, the system will see this as a drug addiction problem. He'd likely be offered probation with Drug Treatment Court, which would give him professional treatment to wean off of the medication and something less harmful which would help him sleep without breaking the law. Additionally it would allow him to come out of this case without getting a criminal record