Here's a version that gets rid of the writer var and Option:

```scala
  def main(args: Array[String]): Unit = {
    val dirPath = new Path(args(0)) // full path to directory
    val numTiles = args(1).toInt
    val numFiles = args(2).toInt
    
    val tilesPerFile = numTiles / numFiles
    val conf = GeotrellisSparkUtils.createHadoopConfiguration
    conf.set("io.map.index.interval", "1");
    val fs = dirPath.getFileSystem(conf)

    val key = new TileIdWritable()
    
    for ((indices,fileIndex) <- 0 until numTiles grouped tilesPerFile zipWithIndex) {
      val mapFilePath = new Path(dirPath, f"part-${fileIndex*tilesPerFile}%05d")
      println(s"Writing to $mapFilePath")
      val writer = 
        new MapFile.Writer(conf, fs, mapFilePath.toUri.toString,
          classOf[TileIdWritable], classOf[ArgWritable],
          SequenceFile.CompressionType.RECORD)
      try {
        for (i <- indices) {
          key.set(i)
          val value = ArgWritable.toWritable(fill(i))
          writer.append(key,value)
        }
      } finally {
        writer.close
      }
    }

    val generator = new SplitGenerator {
      def getSplits = (for(i <- 0 until numTiles by tilesPerFile) yield i.toLong).drop(1).map(_ - 1)
      println(getSplits)
    }
    val splitFile = new Path(dirPath, TileIdPartitioner.SplitFile).toUri.toString
    TileIdPartitioner(generator, splitFile, conf)
  }
```