init_file looks OK. You’re registering an output correctly and you’re doing work in a doLast; however, File initFile = new File("init.txt") isn’t enough to create a file.
So what probably happened, the first time you ran the build, Gradle recorded that the correct state of init.txt after running init_file is to not exist. Since the file doesn’t exist, the task is up-to-date.
You shouldn’t use new File("init.txt") since it will try to create a file relative to the current working directory of the JVM (which might not be in your project directory). You can use file("init.txt") like you used before (it returns a File too).
And then run Gradle with --rerun-tasks, that’ll force the task to re-run and it should behave properly after that (deleting init.txt will cause the task to run again).