As noted on the page of format/2, the escape sequences one uses in practice are interpreted by the Prolog lexer, not by writef/2.
The escape sequences appearing the string of writef/2 are thus already interpreted when writef/2 sees them, and they are those used by the C-library (except for \?). In particular, at that level, \% is an unknown escape sequence and leads to an error:
?- writef("\%").
ERROR: Syntax error: Unknown character escape in quoted atom or string: `\%'
To drill through the Prolog lexer, one has to escape the backslash. For example, for the newline:
?- S=">\\n<", string(S)
, atom_string(A,S)
, atom(A)
, string_codes(S,C)
.
S = ">\\n<",
A = '>\\n<',
C = [62, 92, 110, 60].
?- writef(">\\n<")
.
>
<
true.
..... And also
?- writef(">\\%<")
.
>%<
true.
This is also mentioned at
https://eu.swi-prolog.org/pldoc/man?section=charescapes
although in the context of character escapes in atoms, not strings.