You need to "print" the Cookie with the HTTP headers, not as part of the HTML document - so before the two newlines that mark the end of the HTTP headers:
Code:
print <<HTTPHEADERS;
Set-Cookie: username=josht&language=english
Content-type: text/html

HTTPHEADERS