Why do you create two (supposedly) identical File objects? If you create one and then use it twice, then there’s no possibility of a typo in one causing your code to misbehave.
But yes, as Skater901 says, this is a matter of common-or-garden debugging, for which this forum isn’t a good place. As well as adding logging showing which code path it’s taking, I’d also log things like the values of variables like file_exists and class_file, so you can check their values are what you expect.
(Once it’s working, you can either remove the logs, or better still use a logging library and log at a low level such as DEBUG or TRACE, so you can keep the logging in the code, but not see the results until you need them again.)
Also, you can simplify:
var file_exists:Boolean = false
if (File(directory_path + "/" + class_name + ".kt").exists())
file_exists = true
to
val fileExists = File(directory_path + "/" + class_name + ".kt").exists()
Or, better, if you reuse the File object, to:
val fileExists = classFile.exists()
(Note that camelCase, not snake_case, is standard for Kotlin identifiers.)