If you want to fix the code as you have it, change the logger line to:
log(k[i].getName() + " x" + inventory.getAmount(k[i]);
Because right now you're creating a list of items independent of the inventory items - all of the items are going to have a default amount of 1.
Also, just a general suggestion - it would be much simpler to do this as a 'for each' loop than a while loop. While loops and for loops have different designed purposes, and I'd recommend that you read up on it if you want to start creating scripts.
for(Item i: inventory.getItems()) {
if(i != null) {
log(i.getName() + " x" + inventory.getAmount(i));
}
}
Note that this will also repeat items that are inside of your inventory, though. If you want to prevent that, your original method (combined with inventory.getAmount()) of solvency might be better in terms of seeing if it was already stated, possibly by checking the first named index of the item.