"Time's Arrow" was a two part episode--the last in the 5th season and the first of the 6th season. This is one of my favorite episodes and my favorite 2-parter. Teleplay was written by Joe Menosky (Part I)
Michael Piller (Part I) and Jeri Taylor (Part II) and based on the story by Joe Menosky.
The episode is fun and creepy at the same time. The character of Samuel Clemens, played by Jerry Hardin, is a nice and amusing aspect to the show and provides comic relief in contrast to the aliens who are invading 19th century Earth to drain the neural energy from humans for food.
The Enterprise is recalled to Earth after a team of scientists discover strange artifacts that are believed to be 500 years old. One of these items is Data's head, hence the reason for the ship's journey back to Earth.
Counselor Troi senses a human presence in the area and experiences strong emotions of pain and suffering. The crew conducts experiments using sensor frequencies and finds an alien race that is doing something to the humans. Data is most adept at seeing these aliens and is thrust through a time portal in the time period of the artifacts; 19th century San Francisco. Guinan talks the captain into going with the away team because if he doesn't, they will never meet.
The crew builds another phase converter and goes through the time portal and their next task is to find Data and stop the aliens, who we learn are absorbing life energy from humans as a means of food. Their victims are people who no one is surprised at their deaths---the old, the sick, and the poverty stricken. The deaths are passed off as cholera.
Meanwhile, Data is busy working to blend in with the new society. A citizen assumes the stranger is a Frenchman and thus Data passes himself off as one. He joins a poker game and uses the earnings to get himself a room in a hotel that's bellhop is the future-famous novelist Jack London. Data enlists the help of London by giving him money in exchange for purchasing items that will help in building a phase converter. London brings Data back a newspaper where Data sees Guinan's picture and a headline announcing her hosting a reception for Samuel Clemens, AKA Mark Twain. He attends the reception and explains to Guinan his purpose for being there. The conversation is overheard by Clemens.
Clemens busies himself with a local reporter and tells him that people from the future are up to no good and plans to gather evidence against them. He sneaks into Data's room, with the help of London, and discovers his "invention" and takes the transceiver part of it and hides in the closet when Data comes back with Guinan. Data and Guinan hear him drop the part when Data tells Guinan that it is made of highly toxic material.
The Enterprise crew, meanwhile, are now dressed in period clothing in a boarding house and hounded by a landlady demanding rent. Picard does his best to ward her off to stall for time and convinces her they are an acting troupe rehearsing for a play and can pay her after the show begins. Then they go to a hospital ward and Geordi detects through his visor residue patterns of the aliens. They set up detectors to pick the aliens out and a couple of them show up and are thwarted by the crew before they can kill more patients. They meet Data who is driving a horse drawn carriage.
Guinan meets Picard for the first time. The crew discuss ways to stop the aliens and go back to the future when they are interrupted by Clemens who once again threatens to expose them. The aliens show up for their conduit (a device designed to resemble a cane with snake head) and Data gets caught in the surge and literally loses his head. Clemens sees the porthole left by the aliens and runs through it, ending up in the 24th century. They go back to the Enterprise with Data's headless body. Clemens greets Worf with "a werewolf?"
On the ship, Clemens talks to Troi about what Earth is like in the 24th century while Geordi is busy putting Data back together again. They meet up and Clemens apologizes for misjudging them and what they were trying to accomplish.
The alien, who missed the portal, tells Picard that the weapons the Enterprise plans to use to destroy their plot will only enhance the time distortion. This will destroy the Earth itself. Picard manages to send a message to the crew in the future via Data's positronic circuitry and the plan to fire photon torpedoes at the alien habitat are stopped in time. They reconfigure the weapons and Clemens is sent back to the past to relay a message to Picard from Geordi---use a certain frequency wave on his phaser which will activate the conduit and allow Picard to return.