Yeoman - Add custom config to gruntfile

Using Yeoman, I have the following in my app/index.js file:

this.src.copy("_gruntfile.js", this.appName + "/Gruntfile.js");

I have a fully crafted _gruntfile.js file that I am trying to copy over to the generated project. This works perfectly fine.

However, I want to dynamically add to the initConfig of my gruntfile later on. I tried this by creating another function in my app/index.js file as so:

addLessTask: function () {
        if (this.styleType === 'less') {
            this.gruntfile.insertConfig("less", "{ \n" +
                                            "development: { \n" +
                                                "files: { \n" +
                                                    "'style/main.css': 'style/main.less true' \n" +
                                                "} \n" +
                                            "} \n" +
                                        "} \n"
            );

          this.gruntfile.registerTask('default', 'less');

        }
    }

Ideally, this would take the already copied _gruntfile.js and add the above to the completed and outputted Gruntfile.js file.

Instead, it created a new Gruntfile.js file in the directory the generator is ran in, and also keeps the Gruntfile.js file in the directory created by the yeoman generator.

How can I dynamically edit my Gruntfile.js in the directory created by my generator instead of creating a new one?