make custom user agent change permanent

You can set it with defaults write:

defaults write com.apple.Safari CustomUserAgent "\"useragentstring\""