It may not be the problem you're experiencing, but it should be pointed out that ! is
generally seen as a special character in interactive shells. It has the function of starting a history expansion, and if followed by a number or string that references a previous command, it will insert it into the current command at that location. It will also likely spit out an error if followed by something unrecognized as one.
This even works inside of double quotes, but single quotes or the backslash will escape it.
Try this, for example:
echo "Hi?" | sed "s/?/!!/"
expands to the previous command entered, so you'll probably get something like Himplayer pr0n.avi
as a result.
Note though that this isn't usually a problem in scripts, only the command line. See the HISTORY EXPANSION section in the bash man page for details.