Note that the "~" notation (used on Unix to indicate the user's home directory) is not resolved into a valid path by open/4 ... which is normal as it is actually a shell convention: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html (not sure it is even POSIX).
The C function to examine the user database and get home directories (among others) of some user X is
In SWI-Prolog, expand_file_name/2 can be used:
?- expand_file_name("~", Home). Home = ['/home/paquette']. ?- expand_file_name("~root", Home). Home = ['/root'].