tomcat: use inreplace, string interpolation

- use inreplace to modify file in place instead of reading file contents into memory and using gsub as per suggestion from @mikemcquaid
- use string interpolation for HOMEBREW_PREFIX as per suggestion from @mikemcquaid
- quote command line arguments to keytool as per suggestion from @mikemcquaid