is_user_logged_in() may not work, if the script is outside of wp folder ?? … yet, i am not sure about that.
Confirmed, I had the same problem and the dozen other threads on the internet did not have anyone mentioning this (or I didn’t read the manual right).
Wrong Way
./test.php
./wordpress/wp-blog-header.php
Correct Way
./wordpress/test.php
./wordpress/wp-blog-header.php