The inspiration for "The Enemy Within" is the classic Dr. Jekyll and Mr. Hyde, but Star Trek
used science fiction in retelling the story. That said duplicates, evil or otherwise, had been done before in comics at least. Superman had been duplicated in good and evil forms. Mind you the Trek writers might not have been aware of it having been done in comics. And it could well have been done in SF literature before TOS.