You have to make sure that no text has been printed on the page before you put that in. If there is text printed (echoed) before that line, the headers will already be set, and it won't work.
I would put that at the very top of the page, followed by a die.