Extension Help

Hi My name is Rodrigo and I am trying develop an extension to organize my Downloads folder, and for now my extension can direct the files of each extension to specific folder, but the files downloaded stay in root of downloads folder, in the specific folders the file is all right.
My question is why the file are duplicated?

some informations:

my script to manage the extensions:

    function handleCreated(item) {
  Url = (item.url);
  Path = (item.filename).split("/");
  filename = Path[(Path.length-1)];
  ext = filename.split(".")[filename.split(".").length-1];

  switch (ext) {
    case "jpg":
      folder="Imagens/" + filename;
      break;

    case "pdf":
      folder = "PDF's/" + filename;
      break;

      case "mp3":
        folder = "Musicas/" + filename;
        break;
    default:
      document.write("default");
      break;
  }

  var downloading = browser.downloads.download({
    url : Url,
    filename :  folder,
    conflictAction : 'uniquify'
  });
  browser.downloads.onCreated.removeListener(handleCreated);
}

browser.downloads.onCreated.addListener(handleCreated);//trigger

Well. For every download, you create another one.

I’m actually surprised that this doesn’t create an infinite asynchronous recursive loop – I guess the documentation is incorrect.