Charlie is a code-word for the letter 'C', as in "Alpha, Bravo, Charlie..." As that is the opening letter of 'cocaine', 'Charlie' was clearly a sensible choice as a nickname. In much the same way, heroin is often called 'H' and that was expanded into 'horse'. I suppose 'hotel' - the usual British phonetic version of 'H' - seemed a bit weak! ("Hey, buddy, got any hotel?" doesn't really have the right ring to it, does it?)
I always assume it was from the cartoon Charlie Chalk, seeing how it looks very much like chalk and then that being shortend to just Charlie. A few people I know still do call it chalk.