Instead of file_exists, I would just check if anything is stored in $cookie_name.
Example,
<?php
if ($cookie_name != "") { //cookie is not blank
do something(?);
}
else { //set the cookie
setcookie("cookie_name", $value, time());
}
?>
<head>
<?php
echo("$name");
?>