The DS18B20 is a digital temperature sensor.
The code that you are using is for an analogue temperature sensor, that is the reason that it gives unexpected results.
There is a tutorial about using the DS18B20 at:
https://lastminuteengineers.com/ds18b20-arduino-tutorial/