What is a safer way to write this applescript
A much safer way is just to action the menu directly.

clear() { osascript \
  -e 'tell application "System Events" to tell process "Terminal"' \
  -e   'click menu item "Clear to Start" of menu 1 of menu bar item "Edit" of menu bar 1' \
  -e 'end tell' \
  -e 'return'
}