~ character is a special, active character which stands for an unbreakable space, i.e. the line will not be broken at this space.
To typeset the tilde as character use
textcomp package provides a lower tilde as
To write a tilde to an auxiliary file use