Misc script flakes

Remove unused variables, remove globals, and in replace.py
avoid re-using old & new.

Change-Id: Idf4ff0f72b9b625f3441754d66272b2315b2fd78