" Breaking Bad " creator Vince Gilligan cast Bryan Cranston for the role of Walter White based on having worked with him in an episode of the science fiction television series " The X-Files " , on which Gilligan worked as a writer .