Cookies are sent in the headers of the transmission of the HTTP page. Once you give some output, you cannot modify these anymore.
The problem in your case lies in you outputting some of the HTML-document before trying to set the cookie.
There are a few ways to solve it; one of which is setting the cookie prior to outputting anything on the page like so
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
</body>
</html>
Alternatively, you could buffer your output so that nothing gets written until you explicitly tell it to
<?php
ob_start(); // Initiate the output buffer
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
?>
</body>
</html>
<?php
ob_end_flush(); // Flush the output from the buffer
?>
For more information on this last approach, take a look at the ob_start and ob_end_flush functions.
It might be useful to read about setcookie, too.