The heated exchange came at the High Court in Edinburgh when defence QC Donald Findlay again accused Strathclyde Police of trying to cover up a botched investigation more than 27 years ago.
A jury heard trial judge Lord Stewart warn John O'Neill, 61, that he would not be released from his duty as a witness pending further investigation.
The naked body of teenage Miss Doyle was found in a lane near her Greenock home on June 2, 1986.
Mr O'Neill was questioned at length about whether Elaine's body was covered with a police-issue "prisoner blanket".
In a statement in June 2012 Mr O'Neill told officers: "I do recall the idea being discussed at the locus that Elaine should be covered up to prevent people seeing the deceased." But in the witness box yesterday Mr O'Neill said he was not so sure.
Mr Findlay said to him: "When you mention the blanket on the body, amnesia flows through the veins like a disease."
Mr O'Neil was handed a book of photos and the lawyer challenged: "Look at it. Now tell me the truth. Have you no shame, sir?"
"Of course I have," replied Mr O'Neill. But he continued to insist that - whatever he said in his earlier statement - he was confused.
Mr Findlay asked: "Can you imagine the consequences for a man like you of going to prison for perjury?"
The trial continues.