Unless you've worked with one, then don't write your own. I'm serious. I maintain and extend one as my day job that I inherited and unless you've done that you should *not* think you can write one from scratch.
There are numerous ones that run web-based that can get you started. RT is perl-based, but quite popular and not too difficult to customise. There's also SugarCRM that I've only seen. It's in PHP. Both are open-source.
We've also looked at at least two commercial offerings and very quickly found limitations. Hosted services, for example, don't like 50Gb of database to import.
Wade.