current output stream
At any given time, input to Prolog goes to the "current output stream". When Prolog starts up, the current output stream is the window or console of the computer/workstation from which Prolog was started. In other words, when your program writes things using the predicates described in the article on writing, they appear on your screen.

However, you might wish to write to somewhere else during the execution of your Prolog program - for example, you might want to write to a file held on the computer on which the program is running, or on some local file server.

To change the current output stream, you use one of the Prolog built-in extra-logical predicates tell and append/1 *. If Prolog executes the goal tell('output.dat'), then output will subsequently go to the file output.dat, in the current working directory of the workstation* that is running Prolog.

If the specified file cannot be found in the current working directory, it will be created. If the file does exist, it will be overwritten. If you use append/1, subsequent write operations will add material to the end of the file, instead of overwriting the file. If you do not have permission to write files in the current directory, you will see an error message:

?- tell('/usr/bin/ztrash').  
ERROR: tell/1: No permission to open source_sink `/usr/bin/ztrash' (Permission denied)

This means that either you do not have permission to write files in the directory /usr/bin, or if the file ztrash already exists in this directory, that you do not have permission to write to that file.

If the file is able to be written, then subsequent write operations send their data to the file. The parameter to tell can be a path to the file that is wanted, as in the example above, or it could be just the file name, e.g. tell('output.dat'). Prolog will continue to issue prompts for more queries and print bindings while you are "telling" or "appending" a file, but any explicit write operations access the file. The built-in extra-logical predicate told (with no argument) allows you to revert to writing data to the original window. Example:

?- tell('info.dat'), write(thirsty(jack)), nl.
true.
?- told, write(drunk(jack)).
drunk(jack)
true.
?- halt.
% cat info.dat # - # is Unix comment char, cat lists info.dat
thirsty(jack)
% 

See also current input stream, input, output, files.

* append/1 is not related to append/3, which in turn has nothing to do with output streams.

# Strictly speaking, output.dat will be expected to be in the current working directory of the command interpreter that started Prolog. The command interpreter will be running on the workstation/computer, and sending output to a window on that workstation or computer.