I went back to this issue today and it turns out that the lattice functions 'do not create plots'. You have to print the object created from the lattice function in order to see/output the graph.
This happens automatically on the command line, which is why I was so confused since the code would work fine outside of a function. If you want your graph to be outputted within a function you have to explicitly print it.
e.g.:
function write_density_plot(data, name) { filename = paste(name, '_density_distribution.png', sep="") png(filename) print(densityplot(data, main=paste(name, 'score distribution')) dev.off() } filedata = read.delim('myfile', header=T) write_density_plot(filedata$blorg, 'blorg') write_density_plot(filedata$blarg, 'blarg') write_density_plot(filedata$wib, 'wib')