Richard Baker wrote:
"A Piece of the Action, pt2"
It was actually planned for TNG Season 7 and they never got around to it. They would have returned to find not old style Gangsters but everyone walking around dressed like Kirk & Spock with tech based on the communicator McCoy left behind in the office.
They were also going to possibly use it as the DS9 throwback episode, but instead decided on Trouble with Tribbles + time travel = Trials and Tribble-ations.