Episodic formation of cometary material in the outburst of a young Sun-like star