If you have produced a well thought-through table of contents or detailed thesis outline, it might not matter when you write your introduction. Still, supervisors frequently recommend that students write an introduction prior to producing a first full draft, even though this will eventually need to be re-written, or tidied up, in order to accommodate changes made during the writing process. Indeed, if you write your introduction early, you will need to check that you have actually done what you said you would do and that your argument in the introduction matches the conclusion.
Writing the introduction early has the advantage of clarifying for you what the overall purpose of the thesis is and precisely what you will be doing in each chapter and why. It will help you to organise your ideas logically and determine what's relevant and what's not in writing your chapters so that the component parts hang together as a whole.