I was watching the original series and got to "I am your father". I thought: is this something the author planned all along or thought of while writing The Empire Strikes Back?
Prowse (the actor who played Vader) was originally told to reveal that it was Obi-Wan who killed Luke's father.
However, the original writer of the script that would become Empire Strikes Back, Leigh Brackett, died before finishing the final draft.
After Leigh's death, Lucas took over writing the script. It was received poorly, likely spurring on the revisions.
Of course, the twist was done by filming and even the actor playing Vader was basically kept unaware of the twist.
Original dialogue: "Obi-Wan killed your father."
The idea of Vader being Luke's father came about in the second draft of The Empire Strikes Back.
From the annotated screenplays:
The notion of Vader being Luke's father first appeared in the second draft. Vader became attracted to the dark side while he was training to become a Jedi. He became a Jedi and killed most of the Jedi Knights. Ben fought Vader and pushed him down a nuclear reactor shaft. One of his arms was severed, and Ben believed he had killed Vader; in fact Vader survived and became a mutant.
While the commitment to reveal the villainous Darth Vader as Luke's father was officially made in the second draft of The Empire Strikes Back, elements of a Darth-Vader-like character being Luke's father were present in the very first drafts of the first film's screenplay, back when it was going to be called The Star Wars. From the Wookieepedia entry for Kane Starkiller (father of Annikin Starkiller, the character who would later be renamed Luke Skywalker):
By the second draft, he becomes known simply as "The Starkiller" and he is the father of Luke Starkiller; he survives to the end of that version and is not a cyborg. In the following story synopsis, he is deleted and replaced by a crazy old man encountered on the road. The notion that Luke's father was a cyborg was incorporated into the story of Darth Vader. Coincidentally, Kane's cyborg body had a chest plate on his torso that resembled a similar chest plate on Vader's life-support armor.
Recently, for The Last Jedi, Mark Hamill discussed the re-working of the scene between the David Prowse line. Most notable about this is that when Hamill is told, only George Lucas and Irvin Kershner (the ESB director) knew it. Hamill had to keep that tidbit under wraps for some 18 months. That apparently irked Carrie Fisher and Harrison Ford, who found out during the screening.
There was a wonderful substitute revelation in that scene. The way we filmed it, Vader said
You don't know the truth. Obi-Wan killed your father
And the idea of Alec Guiness being the real villain, I thought "Wow, what a spectacular twist!" It's just as you see in the film. "Search your feelings, you know, it's true." Wallop the hand goes off...
The director, Irvin Kershner, took me aside -- came to my dressing room actually -- and said
I know it, George Lucas knows it, and when I tell you, you'll know it, but if it leaks, we'll know it was you
So I was like, "What? What?" and he handed me the piece of paper that said "I am your father". I was shocked. I said "Is that true?" and he said "Search your feelings and we're gonna play it like that"
There's some commentary on how loose lipped Carrie Fisher was. Then he says
So, at the screening, when that happened, Harrison turned to me and said "Hey, kid, you didn't f***ing tell me that"