In the movie, it is implied that Lecter somehow stole Chilton's pen and used it to fashion a key for the handcuffs that he expects the Tennessee police to use to restrain him.
In the book, he's been in possession of the key for some time in anticipation of a chance. His interest is piqued by the Senator's offer in part due to the fact that Chilton tells him that the Tennessee police will get custody of him (and he will be out of Crawford's jurisdiction). Quoting from the book:
At Last Dr. Chilton has said something interesting, and he doesn't even know what it is. Dr. Lecter pursed his red lips behind the mask. The custody of police. Police are not as wise as Barney. Police are accustomed to handling criminals. They're inclined to use leg irons and handcuffs. Handcuffs and leg irons open with a handcuff key. Like mine.
Later, Crawford reads the following message on his computer screen:
MEMPHIS POX RECOVERED 2 ITEMS IN SEARCH OF LECTER'S CELL.
(1) IMPROVISED HANDCUFF KEY MADE FROM BALLPOINT TUBE. INCISIONS BY ABRASION, BALTIMORE REQUESTED TO CHECK HOSPITAL CELL FOR TRACES OF MANUFACTURE, AUTH COPLEY, SAC MEMPHIS.