Steven Spielberg is better known as a director, but every now and then, he'll use a typewriter rather than a camera to tell a tale. Typically, he creates story concepts and other writers pen the screenplay. Spielberg also wrote the screenplay for Poltergeist (1982), directed by Tobe Hooper. And while he gets a credit on the 2015 remake because he created the characters, he didn't actually write that one.
We won't hold that against him.
Very rarely, Spielberg will write a screenplay and then direct it himself. The last film to bear this distinction was A.I.: Artificial Intelligence (2001), the Stanley Kubrick project Spielberg took over after the virtuoso's death. Earlier in his career, Spielberg took on this double duty for his short film Amblin' (1968) and, of course, Close Encounters of the Third Kind.
Spielberg said that the concept for Close Encounters came before he started working on Jaws. His original vision was a story about a military guy investigating UFO phenomena in modern America, but he revised his idea slightly after Watergate, deciding to add a dollop of government conspiracy to the proceedings (source). Other commentators have found the origins of Close Encounters in Spielberg's amateur film Firelight, a story of an alien invasion that the director filmed at sixteen. The aliens were a wee-bit more hostile in this outing, though. (Source)
Spielberg wrote the concept sketch—then called Watch the Skies—but he and producers Julia and Michael Phillips initially brought in another writer to pen the script. The writer was Paul Schrader, most famous for writing some of Martin Scorsese's best films: Taxi Driver (1976), Raging Bull (1980), and The Last Temptation of Christ (1988). Anyone who's seen those films can probably guess what happened. Spielberg found Schrader's treatment "absolutely horrendous," and decided to write the script himself with help from his friends Hal Barwood and Matt Robbins. (Source)
If you've seen the final movie, you already know it turned out much different than Spielberg's initial vision. The protagonist was no longer a military man searching for UFOs as part of Project Bluebook-esque program, but everyday schlub Roy Neary. And while the conspiracy elements remain, the Watergate-era distrust of a menacing government was significantly muted by the boyish smiles of François Truffaut's Lacombe.