What design should I use to clean up this pulse wave?
As others have said, a Schmitt trigger will clean it up. Reducing the 51k resistor to 10k or so may help as well.
Also consider this waveform distortion is irrelevant for the typical intended electronic music function of the IC. A perfect 18kHz square wave is barely audible under good conditions. The harmonics of the imperfect square are way above audible frequency. The difference between a perfect square and your signal will not be perceptible in the context of electronic music. In an analog synthesizer, achieving perfect waveshape beyond useful audio frequencies isn't necessarily expected, required, practicable, or audible.